<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/lib/Db.php';

$db = new Db();
// $res=$db->table('cates')->field('id,title')->order('id desc')->where('id>1 and id<9')->limit(5)->lists();
// $data = array('cid' => 3, 'title' => '数据库添加','pv'=>8);
// $id=$db->table('demo_article')->insert($data);
// $res=$db->table('demo_article')->where(array('id'=>4))->delete($data);
// $data=array('title'=>'数据库更新');
// $res=$db->table('demo_article')->where(array('id'=>2))->update($data);
// var_dump($res);
// print_r($res);
// 查询:select
// 插入:insert
// 修改:update
// 删除:delete

// 分页查询
// $cid=$_GET['cid'];  // 分类id
$page = $_GET['page'];    // 第几页
$pageSize = 2;   // 每页加载多少条数据
$res = $db->table('demo_article')->field('id,title')->where('id>2')->pages($page, $pageSize,'/phpblog/text.php');

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分页</title>
    <link rel="stylesheet" type="text/css" href="static/bootstrap/css/bootstrap.min.css">
    <script type="text/javascript" src="static/js/jquery-3.2.0.js"></script>
    <script type="text/javascript" src="static/bootstrap/js/bootstrap.min.js"></script>
</head>

<body>
    <div class="container">
        <p>共查询出<?php echo $res['total'] ?>条数据</p>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($res['data'] as $artice) { ?>
                    <tr>
                        <td><?php echo $artice['id'] ?></td>
                        <td><?php echo $artice['title'] ?></td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>
        <!-- 分页 -->
        <div>
            <?php echo $res['pages']?>
        </div>
    </div>
</body>

</html>